<template>
  <BasicModal
    @register="register"
    title="请给出最终评分和评分依据"
    :okButtonProps="{ disabled: false }"
    :helpMessage="[
      '标准评定任务完成等级说明：',
      'A.已完成：全部完成任务内容；',
      'B.基本完成：完成任务内容的80%以上；',
      'C.正在进行；',
      'D.未开展;',
      '标准评定任务完成等级，目标考核管理系统将按照“目标完成率=已完成的任务数量÷目标任务总数”进行核算（其中任务数量均按照《指标体系》的二级指标进行计数）',
    ]"
    @ok="upTimeLast"
  >
    <div style="margin-bottom: 25px; margin-left: 30px">
      考核等级
      <RadioGroup v-model:value="value2" style="margin-left: 10px" button-style="solid">
        <RadioButton value="A">A</RadioButton>
        <RadioButton value="B">B</RadioButton>
        <RadioButton value="C">C</RadioButton>
        <RadioButton value="D">D</RadioButton>
      </RadioGroup>
    </div>
    <div style="margin-bottom: 25px; margin-left: 30px; margin-top: 10px">
      最终评分
      <!-- :disabled="pinweifenshu.value == null" -->
      <a-input v-model:value="pinweifenshu" style="width: 200px; margin-left: 5px" />
    </div>
    <div style="margin-bottom: 25px; margin-left: 30px">
      评分依据
      <a-textarea
        v-model:value="pinweifenshuneirong"
        style="width: 380px; margin-left: 5px"
        :auto-size="{ minRows: 2, maxRows: 6 }"
      />
    </div>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { Radio } from 'ant-design-vue';
  import { taskInterimMarkPingfenPUT, taskInterimMarkPingfen } from '/@/api/basic/qimo/index';
  import { useMessage } from '/@/hooks/web/useMessage';
  const RadioGroup = Radio.Group;
  const RadioButton = Radio.Button;
  // components: { TimeRangePicker: TimePicker.TimeRangePicker}
  const { createMessage } = useMessage();
  let pinweifenshuneirong: any = ref();
  let pinweifenshu: any = ref();
  let record: any = ref();
  let results: any = ref();
  let yijuNum: any = ref();
  const value2 = ref<string>('A');
  const emit = defineEmits(['success', 'register']);
  const [register, { closeModal }] = useModalInner((data) => {
    // 赋值
    // let a = { ...data };
    // console.log(a, '111111');
    record.value = { ...data?.detailResule };
    results.value = { ...data?.results };
    yijuNum.value = record.value.targetScore;
    // console.log(yijuNum, '测试惆怅长岑长擦擦擦擦擦擦擦擦擦擦擦擦是');
    if (record.value.taskTargetMark) {
      if (
        record.value.taskTargetMark.finalScore &&
        record.value.taskTargetMark.finalRemark &&
        record.value.taskTargetMark.finalLevel
      ) {
        pinweifenshu.value = record.value.taskTargetMark.finalScore;
        pinweifenshuneirong.value = record.value.taskTargetMark.finalRemark;
        value2.value = record.value.taskTargetMark.finalLevel;
      } else {
        pinweifenshuneirong.value = '';
        pinweifenshu.value = '';
        value2.value = 'A';
      }
    } else {
      pinweifenshuneirong.value = '';
      pinweifenshu.value = '';
      value2.value = 'A';
    }
  });
  async function upTimeLast() {
    if (pinweifenshu.value !== undefined && pinweifenshuneirong.value !== undefined) {
      console.log(pinweifenshu, record.value.twoLevelScore, '00000');
      if (Number(pinweifenshu.value) > record.value.twoLevelScore) {
        createMessage.error(`评分不能大于项目分值，请重新填写`);
      } else {
        if (record.value.taskTargetMark) {
          // if (
          //   record.value.taskTargetMark.finalScore &&
          //   record.value.taskTargetMark.selfRemark &&
          //   record.value.taskTargetMark.finalLevel
          // ) {
          const arrchage = {
            id: record.value.taskTargetMark.id,
            twoLevelId: record.value.id,
            finalScore: pinweifenshu.value,
            finalLevel: value2.value,
            finalRemark: pinweifenshuneirong.value,
            tenantId: results.value.tenantId,
          };
          // console.log(arrchage, '222222222222');
          await taskInterimMarkPingfenPUT(arrchage);
          emit('success');
          pinweifenshuneirong.value = '';
          pinweifenshu.value = '';
          value2.value = 'A';
          // } else {
          //   const arr = {
          //     finalScore: pinweifenshu.value,
          //     finalLevel: value2.value,
          //     finalRemark: pinweifenshuneirong.value,
          //     tenantId: results.value.tenantId,
          //     twoLevelId: record.value.id,
          //   };
          //   await taskInterimMarkPingfen(arr);
          //   emit('success');
          //   pinweifenshuneirong.value = '';
          //   pinweifenshu.value = '';
          //   value2.value = '10';
          // }
        } else {
          const arr = {
            finalScore: pinweifenshu.value,
            finalLevel: value2.value,
            finalRemark: pinweifenshuneirong.value,
            tenantId: results.value.tenantId,
            twoLevelId: record.value.id,
          };
          await taskInterimMarkPingfen(arr);
          emit('success');
          pinweifenshuneirong.value = '';
          pinweifenshu.value = '';
          value2.value = 'A';
        }

        closeModal();
        pinweifenshuneirong.value = '';
        pinweifenshu.value = '';
        value2.value = 'A';
      }
    } else {
      createMessage.error(`评分或评分依据不能为空`);
    }
  }
</script>
